#ifndef PF_MESHLINE_H
#define PF_MESHLINE_H

#include <CAD/pf_graphicview.h>
#include <CAD/pf_plot.h>

#include <QVector>
#include <QVector2D>

namespace CommonFEM {
class Line{
public:
    Line(double x1,double y1,double x2,double y2);
    ~Line();

    double m_x1,m_y1;
    double m_x2,m_y2;
};

/**
 * @brief 一个meshline类，可以绘制出分网。
 *
 */
class PF_MeshLine  : public QCPAbstractItem
{
    Q_OBJECT
    /// \cond INCLUDE_QPROPERTIES
    Q_PROPERTY(QPen pen READ pen WRITE setPen)
    Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
    /// \endcond
public:
    PF_MeshLine(PF_GraphicView *parentPlot);
    virtual ~PF_MeshLine();

    // getters:
    QPen pen() const { return mPen; }
    QPen selectedPen() const { return mSelectedPen; }

    // setters;
    void setPen(const QPen &pen);
    void setSelectedPen(const QPen &pen);

    void clearLines();
    void addLine(double x1,double y1,double x2,double y2);

    // reimplemented virtual methods:
    virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const;

protected:
    // property members:
    QPen mPen, mSelectedPen;

    // reimplemented virtual methods:
    virtual void draw(QCPPainter *painter);

    // non-virtual methods:
    QLineF getRectClippedLine(const QVector2D &start, const QVector2D &end, const QRect &rect) const;
    QPen mainPen() const;
private:
    QVector<Line*> m_linelist;
};
}//namespace CommonFEM


#endif // PF_MESHLINE_H
